#include #include using namespace std; //structures // user defined data-types // the programmer is the user of C++ (the programming language) struct Height { int feet; int inches; }; struct SuperHero { //attributes //members //data-members //member- variables char name[100]; char power[1000]; Height height; int age; //... }; void getSuperHero(SuperHero& s) { cout << "Age? "; cin >> s.age; //empty the input buffer cin.ignore(cin.rdbuf()->in_avail()); cout << "Name? "; cin.getline(s.name, 100); cout << "Power? "; cin.getline(s.power,1000); cout << "Height(feet inches)? "; cin >> s.height.feet; cin >> s.height.inches; } //alwayes pass objects to functions by ref. to avoid the overhead of making a copy //when you do not want the values to change make it const void displaySuperHero(const SuperHero& s) { cout << s.name << " is " << s.age << " years old. "; cout << " He can " << s.power << endl; cout << ". He is " << s.height.feet << "' " << s.height.inches << "\" tall."; } void main() { // object - a variable of a user-defined-data-type SuperHero s; //SuperHero heros[100]; getSuperHero(s); displaySuperHero(s); // int is an example of an intrinsic data-type //int x; } /////////////////////////////////////////////////////////////// #include #include using namespace std; //structures // user defined data-types // the programmer is the user of C++ (the programming language) struct Height { int feet; int inches; }; struct SuperHero { //attributes //members //data-members //member- variables char name[100]; char power[1000]; Height height; int age; //... //member functions void get(); void display(); }; //:: is the socpe resolution operator void SuperHero::get() { cout << "Age? "; cin >> age; //empty the input buffer cin.ignore(cin.rdbuf()->in_avail()); cout << "Name? "; cin.getline(name, 100); cout << "Power? "; cin.getline(power,1000); cout << "Height(feet inches)? "; cin >> height.feet; cin >> height.inches; } //alwayes pass objects to functions by ref. to avoid the overhead of making a copy //when you do not want the values to change make it const void SuperHero::display() { cout << name << " is " << age << " years old. "; cout << " He can " << power << endl; cout << ". He is " << height.feet << "' " << height.inches << "\" tall."; } void main() { // object - a variable of a user-defined-data-type SuperHero s; SuperHero s2; //SuperHero heros[100]; //s.get(); //s.display(); //s2.get(); //s2.display(); SuperHero heros[2]; for(int i = 0; i < 2; i ++) { heros[i].get(); } for(int i = 0; i < 2; i ++) { heros[i].display(); } // int is an example of an intrinsic data-type //int x; }